package design_patterns.factory;

import design_patterns.Calculator;
import design_patterns.impl.AddImpl;
import design_patterns.impl.ExceptImpl;
import design_patterns.impl.MultiplyImpl;
import design_patterns.impl.SubtractImpl;

public class CalculatorFactory {
    public static Calculator getInstance(String operator){
        switch (operator){
            case "+":
                return new AddImpl();
            case "-":
                return new SubtractImpl();
            case "*":
                return new MultiplyImpl();
            case "/":
                return new ExceptImpl();
            default:
                throw new RuntimeException("无效的操作符"+operator);
        }
    }
}
